//
//  UPMineInfo.m
//  Uang Pasti
//
//  Created by 李永彬 on 2025/8/17.
//

#import "UPMineInfo.h"

@implementation UPMineInfo

+ (instancetype)sharedManager {
    static UPMineInfo *instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[UPMineInfo alloc] init];
    });
    return instance;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(handleLogOutOrExpiredAction:)
                                                     name: kLogOutOrExpiredNotificationKey
                                                   object:nil];
    }
    return self;
}

- (BOOL)isLogin {
    if ([UPUserDefaults stringForKey:loginSessionIdKey] == nil) {
        return false;
    } else {
        return true;
    }
}

- (void)handleLogOutOrExpiredAction:(NSNotification *)notification {
    [UPUserDefaults removeObjectForKey: loginSessionIdKey];
}

@end
